{% extends 'TopxiaAdminBundle:Course:layout.html.twig' %}

{% block title %}退款管理 - {{ parent() }}{% endblock %}

{% set script_controller = 'order/refunds' %}

{% set menu = 'refunds' %}

{% block main %}

  <div class="page-header clearfix">
    <h1>退款管理</h1>
  </div>

  <form id="user-search-form" class="form-inline well well-sm" action="" method="get" novalidate>
    <div class="form-group">
      <select class="form-control" name="status">
        {{ select_options(dict('refundStatus'), app.request.get('status'), '退款状态') }}
      </select>
    </div>

    <div class="form-group">
      <input class="form-control" type="text" name="nickname" value="{{ app.request.get('nickname') }}" placeholder="退款人昵称">
    </div>

    <div class="form-group">
      <input class="form-control" type="text" name="courseId" value="{{ app.request.get('courseId') }}" placeholder="课程编号">
    </div>

    <div class="form-group">
      <input class="form-control" type="text" name="orderSn" value="{{ app.request.get('orderSn') }}" placeholder="订单号">
    </div>

    <button class="btn btn-primary">搜索</button>

  </form>

  <table class="table table-striped table-hover" id="refunds-table">
    <thead>
      <tr>
        <th width="50%">退款订单</th>
        <th>订单成交金额</th>
        <th>退款人</th>
        <th>退款状态</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
      {% if refunds %}
        {% for refund in refunds %}
          {% set order = orders[refund.orderId] %}
          {% set user = users[refund.userId] %}
          <tr>
            <td>
              {% if order.targetType == 'course' %}
                <a href="{{ path('course_show', {id:order.targetId}) }}" target="_blank">{{ order.title }}</a>
              {% else %}
                {{ order.title }}
              {% endif %}
              <div class="text-muted text-sm">订单号：{{ order.sn }} | 成交时间：{{ order.createdTime|date('Y-n-d H:i') }}</div>
              <div class="text-muted text-sm">退款理由：{{ refund.reasonNote }} | 退款时间：{{ refund.createdTime|date('Y-n-d H:i') }}</div>
            </td>
            <td>{{ order.amount }}元</td>
            <td>
              {{ admin_macro.user_link(user) }}
            </td>
            <td>
              {{ dict_text('refundStatus:html', refund.status) }}
              {% if refund.status == 'success' %}
                <div class="text-sm text-muted">实退{{ refund.actualAmount }}元</div>
              {% endif %}
            </td>
            <td>
              {% if refund.status == 'created' %}
                <button class="btn btn-sm btn-primary confirm-refund" type="button" data-target="#modal" data-toggle="modal" data-url="{{ path('admin_order_audit_refund', {id:order.id}) }}">审核</button>
                <button class="btn btn-sm btn-default cancel-refund" type="button" data-url="{{ path('admin_order_cancel_refund', {id:order.id}) }}">取消</button>
              {% endif %}
            </td>
          </tr>
        {% endfor %}
      {% else %}
        <tr><td colspan="20"><div class="empty">暂无退款记录</div></td></tr>
      {% endif %}
    </tbody>
  </table>

{% endblock %}
